package com.comtime.view;


import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.NumberPicker;
import android.widget.NumberPicker.OnValueChangeListener;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.comtime.smartkilimanjaro.R;


public class SelectNameModePopupWindow extends PopupWindow {

	private MyNumPicker times;
	private Button btn_ok,btn_cancel;
	private TextView tv_title; 
	private View mMenuView;

    private String[] displayedValues;
	
	public SelectNameModePopupWindow(Context context,
			OnClickListener itemsOnClick,
			OnValueChangeListener valueChangeListener, int currentrvalue,String[] values) {
		super(context);
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mMenuView = inflater.inflate(R.layout.popupwindow_select_alarm_times,
				null);
		displayedValues=values;
		btn_ok = (Button) mMenuView
				.findViewById(R.id.btn_setting_selectalarmtimes_ok);

		times = (MyNumPicker) mMenuView
				.findViewById(R.id.numberPicker_setting_times);
		if(displayedValues.length==2){
			times.setMaxValue(1);
		}else{
			times.setMaxValue(displayedValues.length-1);
		}
		times.setMinValue(0);
		times.setDisplayedValues(displayedValues);
		times.setFocusable(true);
		times.setClickable(false);
		times.setFocusableInTouchMode(true);
		Log.i("tag","currentrvalue"+currentrvalue);
		times.setValue(currentrvalue);
		times.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
		// ���ð�ť����
		btn_ok.setOnClickListener(itemsOnClick);
		times.setOnValueChangedListener(valueChangeListener);

		// ����SelectPicPopupWindow��View
		this.setContentView(mMenuView);
		// ����SelectPicPopupWindow��������Ŀ�
		this.setWidth(LayoutParams.MATCH_PARENT);
		// ����SelectPicPopupWindow��������ĸ�
		this.setHeight(LayoutParams.WRAP_CONTENT);
		// ����SelectPicPopupWindow��������ɵ��
		this.setFocusable(true);
		// ����SelectPicPopupWindow�������嶯��Ч��
		this.setAnimationStyle(R.style.AnimBottom);
		// ʵ��һ��ColorDrawable��ɫΪ͸��
		ColorDrawable dw = new ColorDrawable(0x00000000);
		// ����SelectPicPopupWindow��������ı���
		this.setBackgroundDrawable(dw);


	}
	
	public SelectNameModePopupWindow(Context context,
			OnClickListener itemsOnClick,
			OnValueChangeListener valueChangeListener,int currentNum,int MaxValue,int MinValue){
		super(context);
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mMenuView = inflater.inflate(R.layout.popupwindow_select_alarm_times,
				null);
		btn_ok = (Button) mMenuView
				.findViewById(R.id.btn_setting_selectalarmtimes_ok);

		times = (MyNumPicker) mMenuView
				.findViewById(R.id.numberPicker_setting_times);
		times.setMaxValue(MaxValue);
		times.setMinValue(MinValue);
		times.setFocusable(true);
		times.setClickable(false);
		times.setFocusableInTouchMode(true);
		times.setValue(currentNum);
		times.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
		
		btn_ok.setOnClickListener(itemsOnClick);
		times.setOnValueChangedListener(valueChangeListener);

		// ����SelectPicPopupWindow��View
		this.setContentView(mMenuView);
		// ����SelectPicPopupWindow��������Ŀ�
		this.setWidth(LayoutParams.MATCH_PARENT);
		// ����SelectPicPopupWindow��������ĸ�
		this.setHeight(LayoutParams.WRAP_CONTENT);
		// ����SelectPicPopupWindow��������ɵ��
		this.setFocusable(true);
		// ����SelectPicPopupWindow�������嶯��Ч��
		this.setAnimationStyle(R.style.AnimBottom);
		// ʵ��һ��ColorDrawable��ɫΪ͸��
		ColorDrawable dw = new ColorDrawable(0x00000000);
		// ����SelectPicPopupWindow��������ı���
		this.setBackgroundDrawable(dw);
	}
	
	public SelectNameModePopupWindow(Context context,
			OnClickListener itemsOnClick,
			OnValueChangeListener valueChangeListener, int currentrvalue,String[] values,String title) {
		super(context);
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mMenuView = inflater.inflate(R.layout.popupwindow_select_alarm_times,
				null);
		displayedValues=values;
		btn_ok = (Button) mMenuView
				.findViewById(R.id.btn_setting_selectalarmtimes_ok);

		btn_cancel=(Button) mMenuView
				.findViewById(R.id.btn_setting_selectalarmtimes_cancel);
		tv_title= (TextView) mMenuView
				.findViewById(R.id.btn_setting_selectalarmtimes_title);
		
		btn_cancel.setVisibility(View.VISIBLE);
		tv_title.setVisibility(View.VISIBLE);
		
		tv_title.setText(title+"");
		
		times = (MyNumPicker) mMenuView
				.findViewById(R.id.numberPicker_setting_times);
		if(displayedValues.length==2){
			times.setMaxValue(1);
		}else{
			times.setMaxValue(displayedValues.length-1);
		}
		times.setMinValue(0);
		times.setDisplayedValues(displayedValues);
		times.setFocusable(true);
		times.setClickable(false);
		times.setFocusableInTouchMode(true);
		Log.i("tag","currentrvalue"+currentrvalue);
		times.setValue(currentrvalue);
		times.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
		// ���ð�ť����
		btn_ok.setOnClickListener(itemsOnClick);
		btn_cancel.setOnClickListener(itemsOnClick);
		times.setOnValueChangedListener(valueChangeListener);

		// ����SelectPicPopupWindow��View
		this.setContentView(mMenuView);
		// ����SelectPicPopupWindow��������Ŀ�
		this.setWidth(LayoutParams.MATCH_PARENT);
		// ����SelectPicPopupWindow��������ĸ�
		this.setHeight(LayoutParams.WRAP_CONTENT);
		// ����SelectPicPopupWindow��������ɵ��
		this.setFocusable(true);
		// ����SelectPicPopupWindow�������嶯��Ч��
		this.setAnimationStyle(R.style.AnimBottom);
		// ʵ��һ��ColorDrawable��ɫΪ͸��
		ColorDrawable dw = new ColorDrawable(0x00000000);
		// ����SelectPicPopupWindow��������ı���
		this.setBackgroundDrawable(dw);


	}

}
